class TreeNode {

    public int value;
    public TreeNode left;
    public TreeNode right;
    public int deep;

    public TreeNode(int value) {
        this.value = value;
    }
}

class Test {


     public static void main(String[] args) {

        Integer[] values = {1, 2, 3, 4, 5, null, 6, 7};

        TreeNode node = createTree(values, 0, 1);

        levelSumList(node);

    }

  static TreeNode createTree(Integer[] array, int index, int deep) {
        TreeNode tn = null;
        if (index < array.length) {
            Integer value = array[index];
            if (value == null) {
                return null;
            }
            tn = new TreeNode(value);
            tn.deep = deep;
            tn.left = createTree(array, 2 * index + 1, deep + 1);
            tn.right = createTree(array, 2 * index + 2, deep + 1);
        }
        return tn;
    }

     static void levelSumList(TreeNode root) {

        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();

            ArrayList<Integer> list = map.get(node.deep);
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(node.value);
            map.put(node.deep, list);

            if (node.left != null) {
                queue.add(node.left);
            }
            if (node.right != null) {
                queue.add(node.right);
            }

        }

        ArrayList<Float> integers = new ArrayList<Float>();

        for (List<Integer> list : map.values()) {
            int sum = list.stream().mapToInt(Integer::intValue).sum();
            integers.add((float) sum / list.size());
        }

        System.out.println(integers);

    }
       
                
                            
                                                


}